<template>
	<view class="content">
		<nav-bar title=' ' bgColor="rgba(255,255,255,0)" titleColor="#333333"></nav-bar>
		<view class="search-box">
			<u-search :shape="square" :showAction="false" placeholder="请输入要查询的内容" v-model="keyword"
				@change="searchChange"></u-search>
		</view>
		<view class="picker-box">
			<view class="item-left" @click="areaTap">
				<view class="h1">
					<pickerAddress @change="change">{{txt}}</pickerAddress>
				</view>
				<u-icon name="arrow-down-fill" size="12"></u-icon>
			</view>
			<view class="item-right" @click="classifyTap">
				<view class="h1">
					贷款类型
				</view>
				<u-icon name="arrow-down-fill" size="12"></u-icon>
			</view>
			<!-- <view class="area-popup-box">
				<u-popup :show="areaShow" mode="bottom" @close="close">
					<view class="head-box">
						<view class="left">
							选择城市
						</view>
						<view class="right" @click="close">
							关闭
						</view>
					</view>

					
					<view class="item-box">
						<view class="item" v-for="(item,index) in areaList" @click="areaItemTap(item,index)">
							<view class="name">
								{{item.name}}
							</view>
							<u-icon v-if="item.checkShow" name="checkmark" color="#ff8811" size="18"></u-icon>
						</view>
					</view>
					<view class="bottom">
						<view class="left" @click="resetTap">
							重置
						</view>
						<view class="right" @click="confirmTap">
							确定
						</view>
					</view>
				</u-popup>
			</view> -->
			<view class="class-popup-box">
				<u-popup :show="classifyShow" mode="bottom" @close="close">
					<view class="head-box">
						<view class="left">
							贷款类型
						</view>
						<view class="right" @click="close">
							关闭
						</view>
					</view>
					<view class="item-box">
						<view class="item" v-for="(item,index) in classList" @click="classItemTap(item,index)"
							:class="{'active':item.checkShow}">
							{{item.name}}
						</view>
					</view>
					<view class="bottom">
						<view class="left" @click="resetTap">
							重置
						</view>
						<view class="right" @click="confirmTap">
							确定
						</view>
					</view>
				</u-popup>
			</view>
		</view>
		<view class="container-box">
			<view class="item" v-for="(item,index) in productList" :key="item.id" @click="productPageTap(item)">
				<view class="top">
					<view class="left">
						<u-icon name="https://item.techolic.cn/hjf/Public/appimg/index_product_icon.png"
							size="28"></u-icon>
						<view class="title">
							{{item.name}}
						</view>
					</view>
					<view class="middle" v-for="(tag,index1) in item.tag">
						<u-icon name="https://item.techolic.cn/hjf/Public/appimg/index_product_icon.png"
							size="18"></u-icon>
						<view class="title">
							{{tag}}
						</view>
					</view>
				</view>
				<view class="bottom">
					<view class="left">
						<view class="p1">
							{{item.max_limit}}
						</view>
						<view class="p2">
							最高额度
						</view>
					</view>
					<view class="middle">
						<view class="p1">
							{{item.interest}}
						</view>
						<view class="p2">
							年利率
						</view>
					</view>
					<view class="right">
						查看详情
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		name: "tab-product",
		data() {
			return {
				txt: '选择地址',
				title: 'Hello',
				keyword: '',
				areaShow: false,
				classifyShow: false,
				checkShow: false,
				areaList: [{
						name: "珠海市",
						checkShow: false,
					},
					{
						name: "广州市",
						checkShow: false,
					},
					{
						name: "阳江市",
						checkShow: false,
					}
				],
				classList: [],
				productList: [],
				province: '',
				city: '',
			};
		},
		mounted() {
			app.globalData.index_login = 1;
			app.login();
			console.log(222222);
			this.get_data();
		},
		methods: {
			get_data() {
				var _this = this;
				app._get('index/get_lists', {}, function(res) {
					_this.classList = res.productList;
					_this.productList = res.product;
				});
			},
			productClick() {
				var _this = this;
				var classify_id = '';
				let classList = _this.classList;
				var keyword = _this.keyword;
				var province = _this.province;
				var city = _this.city;
				for (let i in classList) {
					if (classList[i].checkShow == true) {
						if (classify_id == '') {
							classify_id = classList[i].id;
						} else {
							classify_id = classify_id + ',' + classList[i].id;
						}

					}
				}
				console.log(classify_id);
				app._get('index/get_class_data', {
					classify: classify_id,
					keyword: keyword,
					province: province,
					city: city,
				}, function(res) {
					_this.productList = res.product;

				});
			},
			searchChange(e) {
				console.log(e);
				this.keyword = e;
				this.productClick();
			},
			change(data) {
				console.log(data);
				this.province = data.data[0];
				this.city = data.data[1];
				this.txt = data.data.join('');
				console.log(data.data.join(''));
				this.productClick();
			},
			areaTap(e) {
				console.log("点击区域")
				console.log(e)
				let that = this;
				that.areaShow = true;
			},
			classifyTap(e) {
				console.log("点击分类")
				console.log(e)
				let that = this;
				that.classifyShow = true;
			},
			areaItemTap(item, index) {
				// console.log(item)
				// console.log(index)
				let that = this;
				let areaList = that.areaList;
				item.checkShow = !item.checkShow;
			},
			classItemTap(item, index) {
				// console.log(index)
				let that = this;
				let classList = that.classList;
				item.checkShow = !item.checkShow;
			},
			productPageTap(item) {
				uni.navigateTo({
					url: "/pages/productPage/productPage?id=" + item.id
				})
			},
			close(e) {
				let that = this;
				that.areaShow = false;
				that.classifyShow = false;
			},
			resetTap() {
				console.log('重置');
				let that = this;
				let classList = that.classList
				for (let i in classList) {
					classList[i].checkShow = false
				}
				that.classList = classList;
				that.txt = '选择地址';
				that.province = '';
				that.city = '';
			},
			confirmTap() {
				let that = this;
				that.areaShow = false;
				that.classifyShow = false;
				that.productClick();
				//console.log(that.classList);
			}
		}
	}
</script>

<style lang="less">
	page {
		background-image: url('https://item.techolic.cn/hjf/Public/appimg/person_bg.png');
		background-size: cover;
		background-repeat: no-repeat;
		background-position: center center;
	}

	.content {
		width: 750rpx;
		height: auto;
		padding-bottom: 160rpx;

		.search-box {
			padding: 32rpx;
		}

		.picker-box {
			display: flex;
			align-items: center;
			justify-content: space-around;

			.item-left,
			.item-right {
				display: flex;
				align-items: center;
				margin: 0 auto;

				.h1 {
					padding-right: 10rpx;
					font-size: 32rpx;
					color: #1E182F;
				}
			}
		}

		.area-popup-box {
			.head-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx;
				border-bottom: 2rpx solid #f2f2f5;

				.left {
					font-size: 32rpx;
					font-weight: bold;
					color: #000000;
				}

				.right {
					font-size: 24rpx;
					font-weight: bold;
					color: #80c2ff;
				}
			}

			.item-box {
				padding: 30rpx;

				.item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-top: 20rpx;
					padding-bottom: 20rpx;

					.name {
						font-size: 28rpx;
						color: #1E182F;
					}
				}
			}

			.bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx;

				.left {
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;
					margin-right: 20rpx;
					background-color: #fff6e8;
					color: #ff962c;
					font-size: 28rpx;
					text-align: center;
				}

				.right {
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;
					background-color: #ff8811;
					color: #ffffff;
					font-size: 28rpx;
					text-align: center;

				}
			}
		}

		.class-popup-box {
			.head-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx;
				border-bottom: 2rpx solid #f2f2f5;

				.left {
					font-size: 32rpx;
					font-weight: bold;
					color: #000000;
				}

				.right {
					font-size: 24rpx;
					font-weight: bold;
					color: #80c2ff;
				}
			}

			.item-box {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				justify-content: space-between;
				padding: 30rpx;

				.item {
					margin: 20rpx 20rpx 0 0;
					padding: 10rpx 20rpx;
					background-color: #f7f8fa;
					font-size: 28rpx;
					color: #1E182F;
				}

				.active {
					background-color: #fff6e8;
					color: #ffa347;
				}
			}

			.bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx;

				.left {
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;
					margin-right: 20rpx;
					background-color: #fff6e8;
					color: #ff962c;
					font-size: 28rpx;
					text-align: center;
				}

				.right {
					width: 100%;
					height: 80rpx;
					line-height: 80rpx;
					background-color: #ff8811;
					color: #ffffff;
					font-size: 28rpx;
					text-align: center;

				}
			}
		}
	}

	.container-box {
		padding: 32rpx;

		.item {
			background-color: #ffbd98;
			border-radius: 24rpx;
			margin-bottom: 28rpx;

			.top {
				display: flex;
				align-items: center;
				padding: 10rpx 30rpx;

				.left {
					display: flex;
					align-items: center;
					margin-right: 40rpx;

					.title {
						padding-left: 10rpx;
						font-size: 32rpx;
						font-weight: bold;
						color: #7a4305;
					}
				}

				.middle,
				.right {
					display: flex;
					align-items: center;
					margin-right: 40rpx;

					.title {
						padding-left: 10rpx;
						font-size: 20rpx;
						color: #7C4608;
					}
				}

			}

			.bottom {
				display: flex;
				align-items: center;
				justify-content: space-around;
				padding: 32rpx;
				border-radius: 22rpx;
				background-color: #FFE4D0;

				.left {
					text-align: center;
					.p1 {
						font-size: 36rpx;
						color: #FF8811;
						font-weight: bold;
					}

					.p2 {
						font-size: 24rpx;
						color: rgba(#1E182F, .5);
					}
				}

				.middle {
					text-align: center;
					.p1 {
						font-size: 36rpx;
						color: #1E182F;
						font-weight: bold;
					}

					.p2 {
						font-size: 24rpx;
						color: rgba(#1E182F, .5);
					}
				}

				.right {
					padding: 12rpx 24rpx;
					border-radius: 28rpx;
					font-size: 24rpx;
					color: #7C4608;
					background-color: #ffdcb7;
				}
			}
		}
	}

	.fgx {
		height: 160rpx;
		width: 750rpx;
	}
</style>